import cv2 as cv
import pytesseract as pytss


def tesseract_demo(image):
    gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
    cv.imshow('gray',gray)
    ret,binary = cv.threshold(gray,0,255,cv.THRESH_BINARY|cv.THRESH_OTSU)
    cv.imshow('binary', binary)
    kernel = cv.getStructuringElement(cv.MORPH_RECT,(3,3))
    closed = cv.morphologyEx(binary,cv.MORPH_CLOSE,kernel)
    cv.imshow('closed', closed)
    output = pytss.image_to_string(closed)
    print('output:%s'% output)


src = cv.imread('yzm1.jpg',1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo',src)
tesseract_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()